from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *
from .models import *
class Buser(APIView):
    def post(self,request):
        name = request.data.get('name')
        word = request.data.get('word')
        dengji = request.data.get('dengji')
        User.objects.create(name=name,word=word,dengji=dengji)
        return Response('ok')
    def get(self,request):
        ser = User.objects.all()
        huo = UserSer(ser,many=True)
        return Response({'code':200,'list':huo.data})

class Bbook(APIView):
    def post(self,request):
        bname = request.data.get('bname')
        modney = request.data.get('modney')
        waijian = request.data.get('waijian')
        Book.objects.create(bname=bname,modney=modney,waijian_id=waijian)
        return Response('ok')
    def get(self,request):
        tea = Book.objects.all()
        ser = BookSer(tea,many=True)
        return Response({'code':200,'list':ser.data})

class Deng(APIView):
    def post(self,request):
        name = request.data.get('name')
        word = request.data.get('word')
        user = User.objects.filter(name = name,word = word).first()

        if user:
            return Response({'code':200,'userid':user.id})
        return Response({'code':10010,'mes':'用户不存在'})
# Create your views here.
